<template>
	<div class="editor">
		<div ref="editor" style="text-align:left" :id='stoerid'></div>
	</div>
</template>

<script>
	import E from 'wangeditor'
	export default {
		name: 'editor',
		props: [
			"id",
			"editdata"
		],
		data() {
			return {
				editorContent: '',
				rach: '',
				stoerid: this.id,
				editor: {}
			}
		},
		methods: {},
		mounted() {
			this.editor = new E('#' + `${this.stoerid}`)
			// var editor = new E(this.$refs.editor)
			let _self = this
			this.editor.customConfig.zIndex = 100;
			// this.editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
			this.editor.customConfig.onchange = function(html) {
				// 监控变化，同步更新到 textarea
				_self.editorContent = html
			}
			this.editor.customConfig.uploadImgShowBase64 = true // 使用 base64 保存图片
			this.editor.create()
			this.editor.txt.html(this.editdata)
			_self.editorContent = this.editor.txt.html()
		},
		watch: {
			id() {
				this.stoerid = this.id;
			},
			editdata: {
				handler(newName, oldName) {
					this.editor.txt.clear()
					this.editor.txt.html(newName)
					console.log(oldName)
				},
				immediate: false
			}
		}
	}
</script>

<style>
</style>
